package com.gesis.properties;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoaderResourceElements {

	private static final Log log = LogFactory
			.getLog(LoaderResourceElements.class);
	private static LoaderResourceElements loaderResourceElements;

	private LoaderResourceElements() {
	}

	/**
	 * Retorna una �nica instancia de la clase LoaderReourceElements
	 * 
	 * @return loaderReourceElements
	 * 
	 */
	public static LoaderResourceElements getInstance() {
		if (loaderResourceElements == null) {
			loaderResourceElements = new LoaderResourceElements();
		}
		return loaderResourceElements;
	}

	/**
	 * Retorna una cadena los mensajes de error de la aplicaci�n
	 * 
	 * @return loaderReourceElements
	 * 
	 */
	public String getErrorMessageValue(String key) {
		String keyValue = null;
		try {
			FileInputStream error = new FileInputStream(
					LoaderResourceElements.class.getResource(
							"msgError.properties").getFile());
			Properties properties = new Properties();

			properties.load(error);
			keyValue = properties.getProperty(key);
		} catch (IOException e) {
			log.error(e);
		}

		return keyValue;
	}

	/**
	 * Retorna una cadena con el parametro consultado
	 * 
	 * @param keyParameter
	 * @return String parameter
	 */
	public String getLabels(String keyParameter) {
		String keyValue = null;

		try {
			FileInputStream parameter = new FileInputStream(
					LoaderResourceElements.class.getResource(
							"labels.properties").getFile());
			Properties properties = new Properties();
			properties.load(parameter);
			keyValue = properties.getProperty(keyParameter);

		} catch (IOException ioe) {
			log.error(ioe);
		}
		return keyValue;
	}

	/**
	 * Retorna una cadena con el parametro consultado
	 * 
	 * @param keyParameter
	 * @return String parameter
	 */
	public String getParameters(String keyParameter) {
		String keyValue = null;

		try {
			FileInputStream parameter = new FileInputStream(
					LoaderResourceElements.class.getResource(
							"parameters.properties").getFile());
			Properties properties = new Properties();
			properties.load(parameter);
			keyValue = properties.getProperty(keyParameter);

		} catch (IOException ioe) {
			log.error(ioe);
		}
		return keyValue;

	}
}
